<template>
	<view class="payList">
		<view class="remaining">
			<view class="title">账户余额</view>
			<view class="explain">
				<text>充值立享等额积分</text>
				<text>累计积分兑换超值好礼</text>
			</view>
			<view class="num"><text>￥</text>{{remaining_sum}}</view>
		</view>
		<view class="canitainer">
			<view class="top">
				<view class="title">我要充值</view>
				<view class="detail" @click="toRecord">充值明细<uni-icons type="right" size="12" color="#A4A4A4">
					</uni-icons>
				</view>
			</view>
			<view class="list">
				<view class="cont" v-for="(item,i) in recommendList" :key="i">
					<view class="tit">超级优惠</view>
					<view class="presented">充<text>{{item.presented}}</text>元</view>
					<view class="recharge_amount">享受球台消费{{item.rechargeAmount}}折</view>
					<button @click="pay(item.rid)">立即充值</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getUserDetail,
		getRechList,
		wechatPay,
		payStatus
	} from "@/api/getData.js";
	export default {
		data() {
			return {
				remaining_sum: 688,
				recommendList: [{
						rId: 0,
						recharge_amount: 100,
						presented: 5,
						recommend: 0
					},
					{
						rId: 1,
						recharge_amount: 300,
						presented: 20,
						recommend: 1
					},
					{
						rId: 2,
						recharge_amount: 500,
						presented: 50,
						recommend: 0
					},
					{
						rId: 2,
						recharge_amount: 500,
						presented: 50,
						recommend: 0
					}
				],
				storeId: null
			}
		},
		onLoad(options) {
			this.storeId = options.storeId
			this.getUserDetail()
			this.getRechList()
		},
		methods: {
			toRecord() {
				console.log(1)
				uni.navigateTo({
					url: "/pages/pay/payRecord"
				});
			},
			pay(rId) {
				this.wechatPay(rId)
			},
			async wechatPay(rId) {
				var _this = this
				const param = {
					orderType: 0,
					id: rId
				}
				const {
					data: res
				} = await wechatPay(param)
				wx.requestPayment({
					timeStamp: res.data.start.timestamp,
					nonceStr: res.data.start.nonceStr,
					package: res.data.pay.packageStr,
					signType: res.data.pay.signType,
					paySign: res.data.pay.paySign,
					success(req) {
						console.log(req)
						_this.payStatus(res.data.paymentId, res.data.start.timestamp, res.data.start.nonceStr,
							res.data.pay.packageStr, res.data.pay.paySign)

					},
					fail(e) {
						console.log(e)
					}
				})
			},
			//支付结果上报
			async payStatus(paymentId, timeStamp, nonceStr, packages, paySign) {
				const param = {
					paymentId: paymentId,
					timeStamp: timeStamp,
					nonceStr: nonceStr,
					packageStr: packages,
					paySign: paySign,
				}
				const {
					data: res
				} = await payStatus(param)
				if (res.data) {
					uni.navigateTo({
						url: "/pages/pay/paymentSuccess?odatetime=" + res.data.odatetime + "&paymentNo=" + res.data.paymentNo + "&type=" + res.data.type + "&price=" + res.data.price + ""
					});
				}

			},
			//用户详情
			async getRechList() {
				const param = {
					storeId: this.storeId
				}
				const {
					data: res
				} = await getRechList(param)
				console.log(res, 22222)
				this.recommendList = res.data
			},
			//用户详情
			async getUserDetail() {
				const {
					data: res
				} = await getUserDetail()
				console.log(res, 22222)
				this.remaining_sum = res.data.surplus
			}
		}
	}
</script>

<style lang="less">
	.payList {
		line-height: 1;

		.remaining {
			height: 473rpx;
			background: url(https://cloudcdn.noitom.com.cn/noitom2/billiard/pay_bg.png) no-repeat;
			background-size: 100% 100%;
			overflow: hidden;
			position: relative;

			.title {
				margin-top: 107rpx;
				margin-left: 142rpx;
				font-size: 32rpx;
				color: #E60012;
				font-weight: bold;
			}

			.explain {
				font-size: 24rpx;
				color: #D79A73;
				line-height: 30rpx;
				margin-left: 142rpx;
				margin-top: 19rpx;

				text {
					display: block;
				}
			}

			.num {
				position: absolute;
				top: 129rpx;
				right: 137rpx;
				font-size: 48rpx;
				font-weight: bold;
				color: #FF5046;

				text {
					font-size: 28rpx;
				}
			}
		}

		.canitainer {
			padding: 0 32rpx;
			margin-top: -60rpx;
			position: relative;
			z-index: 10;

			.top {
				display: flex;
				align-items: center;
				justify-content: space-between;

				.title {
					font-size: 36rpx;
				}

				.detail {
					font-size: 24rpx;
					color: #A4A4A4;
				}
			}

			.list {
				display: flex;
				flex-wrap: wrap;
				margin-top: 32rpx;

				.cont {
					width: 219rpx;
					height: 263rpx;
					background: #FFEDD7;
					border: 1px solid #E6BD9A;
					border-radius: 16rpx;
					overflow: hidden;
					text-align: center;
					margin-right: 15rpx;
					box-sizing: border-box;
					margin-bottom: 16rpx;

					.tit {
						height: 50rpx;
						background: #FEE3CE;
						line-height: 50rpx;
						font-size: 24rpx;
						color: #EA9965;
					}

					.presented {
						font-size: 32rpx;
						font-weight: bold;
						color: #BC6E3C;
						margin: 18rpx 0;

						text {
							font-size: 58rpx;
							color: #E60012;
						}
					}

					.recharge_amount {
						font-size: 24rpx;
						color: #BC6E3C;
					}

					button {
						margin: 28rpx auto 0;
						width: 157rpx;
						height: 49rpx;
						border: 1px solid #F4141F;
						border-radius: 24rpx;
						font-size: 24rpx;
						color: #F4141F;
						line-height: 49rpx;
						padding: 0;
						background: none;
					}
				}

				.cont:nth-child(3n) {
					margin-right: 0;
				}
			}
		}
	}
</style>
